package com.yxj.waitandnotify;

public class Foodie extends Thread{
    public void run() {
        while(true) {
            synchronized(Desk.lock) {
                if(Desk.count == 0) {
                    break;
                }else {
                    if(Desk.foodFlag == 0) {
                        //如果有，就等待
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        //吃的总数-1
                        Desk.count--;
                        //如果有。就开吃
                        System.out.println("吃货正在吃面条，还能再吃"+Desk.count+"碗面条");
                        //吃完之后，唤醒厨师继续做
                        Desk.lock.notifyAll();
                        //修改桌子的状态
                        Desk.foodFlag = 0;
                    }
                }

            }
        }
    }
}
